package export.magicWeapon
{
	import base.*;
	
	import com.greensock.*;
	
	import export.bullet.*;
	
	import flash.events.Event;
	import flash.geom.*;
	
	public class MagicSword2 extends BaseMagicWeapon
	{
		
		public function MagicSword2(param1:BaseHero)
		{
			super(param1);
			this.mp = 30;
		}
		
		private var swordEffect:BaseBullet;
		
		override protected function initBBDC():void
		{
			var _loc1_:* = null;
			var _loc2_:Array = BaseBitmapDataPool.getBitmapDataArrayByName("MagicSwordBmd2");
			if (_loc2_)
			{
				_loc1_ = {
					"name"  : "body",
					"source": _loc2_
				};
				bbdc = new BaseBitmapDataClip([_loc1_], 120, 240, new Point(0, 0));
				bbdc.setOffsetXY(-35, 30);
				bbdc.setFrameStopCount([[10], [9999]]);
				bbdc.setFrameCount([1, 1]);
				bbdc.setAddScriptWhenFrameOver(scriptFrameOverFunc);
				this.addChild(bbdc);
				return;
			}
			throw new Error("MagicSword2--BitmapData Error!");
		}
		
		override public function showSkill():void
		{
			var direct:uint = this.sourceRole.getBBDC().getDirect();
			var bb:SpecialEffectBullet = new SpecialEffectBullet("MagicSword2_1");
			bb.setOwner(this.sourceRole);
			bb.setDisable();
			bb.setAction("idle");
			bb.x = this.sourceRole.x;
			bb.y = Number(this.sourceRole.y) - 50;
			this.sourceRole.magicBulletArray.push(bb);
			gc.gameScene.addChild(bb);
			TweenMax.delayedCall(1, function (param1:MagicSword2, param2:uint):*
			{
				param1.releasesword(param2);
			}, [this, direct]);
			TweenMax.delayedCall(30, function (param1:MagicSword2):*
			{
				param1.setAction("idle");
			}, [this]);
		}
		
		private function releasesword(param1:uint):void
		{
			var _loc6_:Number = NaN;
			var _loc7_:int = 0;
			var _loc8_:BaseMonster = null;
			var _loc2_:SpecialEffectBullet = new SpecialEffectBullet("MagicSword2_2");
			var _loc3_:int = 0;
			var _loc4_:BaseMonster = null;
			var _loc5_:Array = [];
			while (_loc3_ < gc.pWorld.getMonsterArray().length)
			{
				_loc4_ = gc.pWorld.getMonsterArray()[_loc3_] as BaseMonster;
				_loc5_.push({
					"index": _loc3_,
					"dis"  : AUtils.GetDisBetweenTwoObj(_loc4_, this.sourceRole)
				});
				_loc3_++;
			}
			_loc3_ = 0;
			if (_loc5_.length > 0)
			{
				_loc6_ = Number(_loc5_[0].dis);
				_loc7_ = int(_loc5_[0].index);
				while (_loc3_ < _loc5_.length - 1)
				{
					if (_loc6_ > _loc5_[_loc3_ + 1].dis)
					{
						_loc6_ = Number(_loc5_[_loc3_ + 1].dis);
						_loc7_ = int(_loc5_[_loc3_ + 1].index);
					}
					_loc3_++;
				}
				_loc8_ = gc.pWorld.getMonsterArray()[_loc7_];
			}
			if (_loc8_)
			{
				_loc2_.x = _loc8_.x;
				_loc2_.y = _loc8_.y + 15;
				_loc2_.setOwner(this.sourceRole);
				_loc2_.setDirect(param1);
				_loc2_.setAction("magicsword2");
				gc.gameScene.addChild(_loc2_);
				this.sourceRole.magicBulletArray.push(_loc2_);
			}
		}
		
		private function __bulletDestroy(param1:Event):void
		{
			trace("---__bulletDestroy---");
			this.setAction("idle");
			if (this.swordEffect)
			{
				this.swordEffect.destroy();
				this.swordEffect = null;
			}
		}
	}
}
